package com.egreen.system.controller;


import com.egreen.common.Result;

import com.egreen.common.pojo.DTO.system.SystemInformationDTO;
import com.egreen.common.pojo.VO.system.GetSystemInformationVO;
import com.egreen.system.service.ISystemInformationService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author cloudJiang
 * @since 2022-07-16
 */
@RestController
@RequestMapping("/systemInformation")
@Api(tags = "系统信息")
public class SystemInformationController {
    @Autowired
    ISystemInformationService iSystemInformationService;
    /**
     * 用户查看自己的系统信息
     *
     * @return
     */
    @GetMapping("/getAll/{id}")
    @ApiOperation(value = "用户查看自己的系统信息",notes ="getSystemInformation，用户查看自己的系统信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "当前用户自己的id", required = true)
    })
    public Result getSystemInformation(@PathVariable int id){
        List<GetSystemInformationVO> systemInformation = iSystemInformationService.getSystemInformation(id);
        return Result.OK(systemInformation);
    }

    /**
     * 添加系统信息
     */
    @PostMapping("/add")
    @ApiOperation(value = "添加系统信息",notes ="通过调用addSystemInformation方法，添加系统信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "title", value = "消息标题", required = true),
            @ApiImplicitParam(name = "content", value = "消息内容", required = true),
            @ApiImplicitParam(name = "userId", value = "接受消息的用户id", required = true),
            @ApiImplicitParam(name = "adminId", value = "发送消息的管理员id", required = true),
            @ApiImplicitParam(name = "systemInformationDTO", value = "以上属性被封装到这个DTO里")
    })
    public Result addSystemInformation(@RequestBody SystemInformationDTO systemInformationDTO){
        iSystemInformationService.addSystemInformation(systemInformationDTO);
        return Result.OK();
    }

    /**
     * 删除系统信息
     */
    @GetMapping("/delete/{id}")
    @ApiOperation(value = "删除系统信息",notes ="deleteSystemInformation，删除系统信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "消息id", required = true)
    })
    public Result deleteSystemInformation(@PathVariable int id){
        iSystemInformationService.deleteSystemInformation(id);
        return Result.OK();
    }


}

